$(function () {
    let userId = sessionStorage.getItem("userId");
    // console.log(userId, "-----qqq")
    findById(userId);
})

layui.use(['form', 'layer', 'jquery', 'laydate'],
    function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer
            , laydate = layui.laydate;
        //日期
        laydate.render({
            elem: '#birthday',
            trigger: 'click'
        });

        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function () {
            var data = form.val('example');
            alert(JSON.stringify(data));
            // console.log(data,"111111")
        });
        //监听提交
        form.on('submit(edit)',
            function (data) {
                data = data.field;
                // console.log(data,"22222");
                $.ajax({
                    url: '/back/designer/edit',
                    data: data,
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        if (data.msg == 'success') {
                            layer.alert("编辑成功", {
                                    icon: 6
                                },
                                function () {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                        } else {
                            layer.msg("编辑用户失败");
                        }
                    }
                });
                return false;
            });

    });

function findById(id) {
    $.ajax({
        url: '/back/designer/findById',
        data: {id: id},
        dataType: "json",
        type: 'get',
        success: function (data) {
            console.log(data,"kankan");
            setUserData(data.data);
        }
    })
}

//赋值
function setUserData(data) {
    // console.log(data,"赋值");
    layui.use(['form'],
        function () {
            let form = layui.form;
            $("#id").val(data.id);
            $("#designer_name").val(data.designername);
            $("#phone").val(data.phone);
            $("#sex").val(data.sex);
            $("#email").val(data.email);
            $("#introduce").val(data.introduce);
            form.render();//重新渲染
        });

}